var MailCfg = Class.create();
MailCfg.prototype = {
	initialize : function() {
		this.get_profile_content = {
			autosave: true,
			autosavesendmail: true,
			autosavewritemail: 3,
			showsenderaddr: false,
			replytoken: '回复:',
			includeoriginal: 'automatic',
			defaulteditor: 'html',
			pagecount: 20,
			viewheader: 'brief'
		};
		this.showCfgFilter = new Array();
		this.updateCfgFilterName = '';
		this.isDisplayPrompt = false;
		this.cfgSuccPrompt = false;
		this.isWBDisplay='';
		this.isWBDisplayPrompt=false;
		this.signPrompt=false;
		this.mailCfgList = [{
			cfg_id : "initMailCfg",
			name : "配置选项"
		}, {
			cfg_id : "mailCfgParameter",
			name : "基本设置"
		}, {
			cfg_id : "mailCfgSign",
			name : "设置签名"
		}, {
			cfg_id : "mailCfgAddresser",
			name : "发件人信息"
		}, {
			cfg_id : "mailCfgRevert",
			name : "自动回复和转发设置"
		}, {
			cfg_id : "mailCfgRefuse",
			name : "拒收设置"
		}, {
			cfg_id : "mailCfgFilter",
			name : "过滤器"
		}, {
			cfg_id : "mailCfgFilter2",
			name : "高级过滤器"
		}, {
		  	cfg_id : "mailWhiteList",
		  	name : "白名单"
		}, {
		  	cfg_id : "mailAvatar",
		  	name : "邮箱个性头像"
		}, {
			cfg_id: "initChangeSkin",
			name: "换肤"
		}];
		this.setProfileContent(true);
		// 需要代理的事件列表，设置为相对于这个类的全局变量，有助于VIP邮箱的扩展
		this.dlEventList = [];
	},
	
	// 为了方便扩展，提供了为类添加方法的方法；
	// name -> 方法名称
	// func -> 方法函数
	// title -> 当前添加的函数重绘界面之后的title
	// rewrite -> 是否重写已存在的类，（默认重写）
	addMethod: function(name, func, title, rewrite) {
		if(typeof func != 'function') return;
		if(this[name] && rewrite === false) return;
		this[name] = func;
		this.mailCfgList.push({
			cfg_id: name,
			name: title
		});
	},
	// 向事件代理的列表中添加新的事件代理
	addDlEvent: function(dlevt) {
		if(Object.isArray(dlevt)) {
			this.dlEventList = this.dlEventList.concat(dlevt);
		} else if(typeof dlevt == 'object') {
			this.dlEventList.push(dlevt);
		}
	},
	
	initEvent: function() {
		var self = this;
		this.dlEventList = this.dlEventList.concat([
			{name: 's_main_page', exec: function() {
				// mailMainPage();
				changePanel('mainPage');
			}},
			{name: 's_cfg_set', exec: function() {
				changePanel('mailConfiguration', 'mailCfgParameter');
			}},
			{name: 's_cfg_sign', exec: function(){
				changePanel('mailConfiguration', 'mailCfgSign');
			}},
			{name: 's_cfg_sender', exec: function() {
				changePanel('mailConfiguration', 'mailCfgAddresser');
			}},
			{name: 's_cfg_reply', exec: function() {
				changePanel('mailConfiguration', 'mailCfgRevert');
			}},
			{name: 's_cfg_refuse', exec: function() {
				changePanel('mailConfiguration', 'mailCfgRefuse');
			}},
			{name: 's_cfg_filter', exec: function() {
				changePanel('mailConfiguration', 'mailCfgFilter');
			}},
			{name: 's_cfg_white', exec: function() {
				changePanel('mailConfiguration', 'mailWhiteList');
			}},
			{name: 's_cfg_service', exec: function() {
				mobileCfg.openMobileService();
			}},
			{name: 's_cfg_setservice', exec: function() {
				mobileCfg.getSms();
			}},
			{name: 's_cfg_setadvance', exec: function() {
				mobileCfg.getSmsOption();
			}},
			{name: 's_cfg_setlogin', exec: function() {
				login_option.getResult();
			}},
			{name: 's_cfg_setsend', exec: function() {
				sot_load.getList();
			}},
			{name: 's_cfg_setconvey', exec: function() {
				custom_mail_display.loadConfigPanel();
			}},
			{name: 's_cfg_lab', exec: function() {
				mailLab.loadConfigPanel();
			}},
			{name: 's_cfg_parameter', exec: function() {
				self.setMailCfgParameter();
			}},
			{name: 's_cfg_main', exec: function() {
				changePanel('mailConfiguration', 'initMailCfg');
			}},
			{name: 'lab_cfg_parameter', exec: function() {
				mailLab.saveCfg();
			}},
			{name: 'lab_cfg_main', exec: function() {
				changePanel('mailConfiguration', 'initMailCfg');
			}},
			{name: 's_cfg_upload', exec: function(EL) {
				mailUploadFile.imageUpload(EL.parentNode);
			}},
			{name: 's_cfg_save_sign', exec: function() {
				self.setCustomSign();
			}},
			{name: 's_cfg_cancel_sign', exec: function() {
				self.hiddenImg();
			}},
			{name: 's_cfg_set_sign', exec: function() {
				self.setMailCfgSign();
			}},
			{name: 's_cfg_sign_preview', exec: function() {
				// self.lightBox.start();
				self.mailSignPreview();
			}},
			{name: 's_cfg_set_sender', exec: function() {
				self.setMailCfgAddresser();
			}},
			{name: 's_cfg_set_sender', exec: function() {
				self.setMailCfgAddresser();
			}},
			{name: 's_cfg_set_reply', exec: function() {
				self.setMailCfgRevert();
			}},
			{name: 's_cfg_set_filter', exec: function() {
				self.setMailCfgFilter();
			}},
			{name: 's_cfg_set_addfilter', exec: function() {
				self.setMailCfgAddFilter();
			}},
			{name: 's_cfg_set_filter2', exec: function() {
				changePanel('mailConfiguration', 'mailCfgFilter2');
			}},
			{name: 's_cfg_set_filter1', exec: function() {
				changePanel('mailConfiguration', 'mailCfgFilter');
			}},
			{name: 's_cfg_set_white', exec: function(EL) {
				self.mailCheckWhiteOnly(EL);
			}},
			{name: 's_cfg_set_addwhite', exec: function() {
				self.setMailCfgAddWhite();
			}},
			{name: 's_cfg_reset_white', exec: function() {
				self.resetValue('white_textarea');
			}},
			{name: 's_cfg_set_refuse', exec: function() {
				self.setMailCfgRefuse();
			}},
			{name: 's_cfg_reset_black', exec: function() {
				self.resetValue('black_textarea');
			}},
			{name: 's_cfg_set_login', exec: function() {
				login_option.setResult();
			}},
			{name: 's_cfg_deleteconvey', exec: function() {
				custom_mail_display.deleteNow();
			}},
			{name: 's_skin_item', exec: function(el) {
				self.setSkinChange(el);
			}}
		]);
		var _gpcn = Element.getParentNodeByClassName;
		DOM.mailConfiguration.observe('click', function(event) {
			var EL = $(event.target);
			self.dlEventList.each(function(item) {
				try {
					var e = _gpcn(EL, item.name);
					if (e) {
						item.exec(e);
					}
					if(e && e.nodeName.toLowerCase() == 'a') {
						Event.stop(event);
					}
				} catch(e) {}
				return false;
			});
			return false;
		}).observe('mouseover', function(event) {
			var e = event.target,
			el = _gpcn(e, 's_skin_item'), ela = el ? el.getAttribute('isfocus') : null;
			if(ela && ela == 'true') return false;
			if(el) {
				$(el).addClassName('skin-item-hover');
			}
			Event.stop(event);
			return false;
		}).observe('mouseout', function(event) {
			var e = event.target,
			el = _gpcn(e, 's_skin_item'), ela = el ? el.getAttribute('isfocus') : null;
			if(ela && ela == 'true') return false;
			if(el) {
				$(el).removeClassName('skin-item-hover');
			}
			Event.stop(event);
			return false;
		});
	},
	
	setSkinChange: function(el) {
		// some change code ...
		try {
			var es = el.getAttribute('skin');
			if(es) changeMailSkin(es);
		} catch(e) {}
		try {
			if(this.focus_skin_item) {
				this.focus_skin_item.removeClassName('skin-item-hover').setAttribute('isfocus', '');
			}
			$(el).addClassName('skin-item-hover').setAttribute('isfocus', 'true');
			this.focus_skin_item = $(el);
		} catch(e) {}
	},

	setProfileContent : function(init) {
		if (init && PROFILE && PROFILE != null) {
			this.init(PROFILE);
		} else {
			profile_get({}, this.init.bind(this));
		}
	},

	init : function(ret) {
		this.get_profile_content = ret;
		PAGE_CAPACITY = this.get_profile_content.pagecount > 0
				? this.get_profile_content.pagecount
				: 20;
	},

	getProfileContent : function() {
		return this.get_profile_content;
	},
	
	// 进入换肤界面
	initChangeSkin: function(rsh) {
		hiddenAllPanel();
		var data = {
			focus_class_blue:'',
			focus_class_green:'',
			focus_class_default:'',
			focus_class_grey:'',
			focus_class_red:'',
			focus_class_lowcarbon:'',
			isfocus_blue:'',
			isfocus_green:'',
			isfocus_default:'',
			isfocus_grey:'',
			isfocus_red:'',
			isfocus_lowcarbon:''
		};
		var pf = this.getProfileContent().user_skin;
		pf = pf ? pf : 'blue';
		if(pf) {
			data['focus_class_' + pf] = 'skin-item-hover';
			data['isfocus_' + pf] = 'isfocus="true"';
		}
		DOM.mailConfiguration.show().innerHTML = new Template(mailCfgChangeSkin).evaluate(data);
		this.focus_skin_item = $(DOM.mailConfiguration.getElementsByClassName('skin-item-hover')[0]);
		changeToolbarStyle('mailConfiguration');
		addAjaxHistory("initChangeSkin", "changePanel('mailConfiguration','initChangeSkin', true)",this.getCfgNameByCfgId("initChangeSkin"), rsh);
	},

	initMailCfg : function(rsh, callBackFunc) {
		if (!callBackFunc || callBackFunc == null) {
			profile_get({}, this.initMailCfgCallBack.bind(this, rsh));
		} else {
			profile_get({}, callBackFunc.bind(this, rsh));
		}
	},

	initMailCfgCallBack : function(rsh, ret) {
		hiddenAllPanel();
		this.get_profile_content = ret;
		this.isDisplayPrompt = false;
		if(typeof(this.get_profile_content.pagecount) != "undefined") {
			PAGE_CAPACITY = this.get_profile_content.pagecount;
		}
		if(typeof(this.get_profile_content.autosavewritemail) != "undefined") {
			IntervalConst.autoStore = parseInt(this.get_profile_content.autosavewritemail) * 60;
		}
		if(typeof(this.get_profile_content.isconference) != 'undefined') {
			isConferenceMode = this.get_profile_content.isconference;
			/*
			if(isConferenceMode) {
				if(!DOM.is_use_con) DOM.is_use_con = $('is_use_con');
				DOM.is_use_con.className = '';
				DOM.is_use_con.innerHTML = '';
			} else {
				tryConferenceMode();
			}
			*/
		}
		// var t = new Template(mailCfgTemplate);
		// var data = new Array();
		DOM.mailConfiguration.innerHTML = mailCfgTemplate;
		DOM.mailConfiguration.show();
		// resizeRightPanel("right");
		changeToolbarStyle('mailConfiguration');
		// changeStyle('');
		this.cfgSuccMsgFunc(this.cfgSuccPrompt);
		this.signMsgFunc(this.signPrompt);
		if(!this.signStyle) this.signStyle = this.loadStyleSign();
		addAjaxHistory("initMailCfg", "changePanel('mailConfiguration','initMailCfg', true)",this.getCfgNameByCfgId("initMailCfg"), rsh);
	},
	
        initLab : function(){
                        mailLab.loadConfigPanel();
                  },
	// 载入设置用户签名的css
	loadStyleSign: function() {
		try {
			var headDOM = document.getElementsByTagName('head')[0];
			var createCss = function(url) {
				var link = document.createElement('link');
				link.setAttribute('rel', 'stylesheet');
				link.setAttribute('href', [MailConst.ALL, '/', url].join(''));
				link.setAttribute('type', 'text/css');
				link.setAttribute('media', 'screen');
				headDOM.appendChild(link);
				link = null;
			};
			// 载入css,(预览签名所用的css)
			var _t_css1 = setTimeout(function() {
				clearTimeout(_t_css1);
				_t_css1 = null;
				createCss('xstyle.css');
			}, 100);
			// 载入css,(签名切图的css)
			var _t_css2 = setTimeout(function() {
				clearTimeout(_t_css2);
				_t_css2 = null;
				createCss('cropper.css');
			}, 200);
		} catch(e) {}
		return true;
	},

	mailCfgParameter : function(rsh) {
		profile_get({}, this.mailCfgParameterCallBack.bind(this, rsh));
	},
	mailCfgParameterCallBack : function(rsh, ret) {
		this.get_profile_content = ret;
		var t = new Template(mailCfgParameterTemplate);
		var data = new Object();
		/*
		if (!this.get_profile_content.autosave) {
			data['autosave'] = '<input type="radio" name="cfg_autosave" id="cfg_autosave" value="true" />打开<input type="radio" checked name="cfg_autosave" id="cfg_autosave" value="false" />关闭';
		} else {
			data['autosave'] = '<input type="radio" checked name="cfg_autosave" id="cfg_autosave" value="true" />打开<input type="radio" name="cfg_autosave" id="cfg_autosave" value="false" />关闭';
		}
		*/
		// data['autosave'] = '<input type="radio" checked name="cfg_autosave" id="cfg_autosave" value="true" disabled="true" />打开<input type="radio" name="cfg_autosave" id="cfg_autosave" value="false" disabled="true" />关闭';
		if (!this.get_profile_content.autosavesendmail) {
			data['autosavesendmail'] = '<input type="radio" name="cfg_autosavesendmail" id="cfg_autosavesendmail" value="true" />打开<input type="radio" checked name="cfg_autosavesendmail" id="cfg_autosavesendmail" value="false" />关闭';
		} else {
			data['autosavesendmail'] = '<input type="radio" checked name="cfg_autosavesendmail" id="cfg_autosavesendmail" value="true" />打开<input type="radio" name="cfg_autosavesendmail" id="cfg_autosavesendmail" value="false" />关闭';
		}
		if (this.get_profile_content.autosavewritemail == 1) {
			data['autosavewritemail'] = '<input type="radio" checked name="cfg_autosavewritemail" id="cfg_autosavewritemail" value=1 />1分钟 <input type="radio" name="cfg_autosavewritemail" id="cfg_autosavewritemail" value=3 />3分钟（推荐） <input type="radio" name="cfg_autosavewritemail" id="cfg_autosavewritemail" value=5 />5分钟 <input type="radio" name="cfg_autosavewritemail" id="cfg_autosavewritemail" value=10 />10分钟 ';
		} else if (this.get_profile_content.autosavewritemail == 5) {
			data['autosavewritemail'] = '<input type="radio" name="cfg_autosavewritemail" id="cfg_autosavewritemail" value=1 />1分钟 <input type="radio" name="cfg_autosavewritemail" id="cfg_autosavewritemail" value=3 />3分钟（推荐） <input type="radio" checked name="cfg_autosavewritemail" id="cfg_autosavewritemail" value=5 />5分钟 <input type="radio" name="cfg_autosavewritemail" id="cfg_autosavewritemail" value=10 />10分钟 ';
		} else if (this.get_profile_content.autosavewritemail == 10) {
			data['autosavewritemail'] = '<input type="radio" name="cfg_autosavewritemail" id="cfg_autosavewritemail" value=1 />1分钟 <input type="radio" name="cfg_autosavewritemail" id="cfg_autosavewritemail" value=3 />3分钟（推荐） <input type="radio" name="cfg_autosavewritemail" id="cfg_autosavewritemail" value=5 />5分钟 <input type="radio" checked name="cfg_autosavewritemail" id="cfg_autosavewritemail" value=10 />10分钟 ';
		} else {
			data['autosavewritemail'] = '<input type="radio" name="cfg_autosavewritemail" id="cfg_autosavewritemail" value=1 />1分钟 <input type="radio" checked name="cfg_autosavewritemail" id="cfg_autosavewritemail" value=3 />3分钟（推荐） <input type="radio" name="cfg_autosavewritemail" id="cfg_autosavewritemail" value=5 />5分钟 <input type="radio" name="cfg_autosavewritemail" id="cfg_autosavewritemail" value=10 />10分钟 ';
		}
		if(this.get_profile_content.isconference || typeof this.get_profile_content.isconference == 'undefined') {
			data['isconference'] = '<input type="radio" checked name="cfg_isconference" value="true" />打开 <input type="radio" name="cfg_isconference" value="false" />关闭 ';
		} else {
			data['isconference'] = '<input type="radio" name="cfg_isconference" value="true" />打开 <input type="radio" checked name="cfg_isconference" value="false" />关闭 ';
		}
		if (!this.get_profile_content.showsenderaddr) {
			data['showsenderaddr'] = '<span><input type="radio" checked name="cfg_showsenderaddr" id="cfg_showsenderaddr" value="false" />仅显示发件人姓名 （对方没有设置发件人姓名则显示用户名，例如“'+ USE_SYS.title + USE_SYS.titleident +'”）</span><br /><span style="margin-left:72px;"><input type="radio" name="cfg_showsenderaddr" id="cfg_showsenderaddr" value="true" />显示姓名和邮件地址 （例如“'+ USE_SYS.title + USE_SYS.titleident +'&lt;mail@'+ USE_SYS.name +'.com&gt;”）</span>';
		} else {
			data['showsenderaddr'] = '<span><input type="radio" name="cfg_showsenderaddr" id="cfg_showsenderaddr" value="false" />仅显示发件人姓名 （对方没有设置发件人姓名则显示用户名，例如“'+ USE_SYS.title + USE_SYS.titleident +'”）</span><br /><span style="margin-left:72px;"><input type="radio" checked name="cfg_showsenderaddr" id="cfg_showsenderaddr" value="true" />显示姓名和邮件地址 （例如“'+ USE_SYS.title + USE_SYS.titleident +'&lt;mail@'+ USE_SYS.name +'.com&gt;”）</span>';
		}
		if (this.get_profile_content.replytoken == "回复:"
				|| this.get_profile_content.replytoken == "回复\\:") {
			data['replytoken'] = '<input type="radio" checked name="cfg_replytoken" id="cfg_replytoken" value="回复:" />回复：<input type="radio" name="cfg_replytoken" id="cfg_replytoken" value="Re:" />Re：<input type="radio" name="cfg_replytoken" id="cfg_replytoken" value="答复:" />答复：';
		} else if (this.get_profile_content.replytoken == "Re:"
				|| this.get_profile_content.replytoken == "Re\\:") {
			data['replytoken'] = '<input type="radio" name="cfg_replytoken" id="cfg_replytoken" value="回复:" />回复：<input type="radio" checked name="cfg_replytoken" id="cfg_replytoken" value="Re:" />Re：<input type="radio" name="cfg_replytoken" id="cfg_replytoken" value="答复:" />答复：';
		} else if(this.get_profile_content.replytoken == "答复:"
				|| this.get_profile_content.replytoken == "答复\\:") {
			data['replytoken'] = '<input type="radio"  name="cfg_replytoken" id="cfg_replytoken" value="回复:" />回复：<input type="radio" name="cfg_replytoken" id="cfg_replytoken" value="Re:" />Re：<input type="radio" checked  name="cfg_replytoken" id="cfg_replytoken" value="答复:" />答复：';
		}else {
		    data['replytoken'] = '<input type="radio"  checked  name="cfg_replytoken" id="cfg_replytoken" value="回复:" />回复：<input type="radio" name="cfg_replytoken" id="cfg_replytoken" value="Re:" />Re：<input type="radio"   name="cfg_replytoken" id="cfg_replytoken" value="答复:" />答复：';
		}
		if (this.get_profile_content.includeoriginal == "manual") {
			data['includeoriginal'] = '<input type="radio" name="cfg_includeoriginal" id="cfg_includeoriginal" value="automatic" />加入<input type="radio" checked name="cfg_includeoriginal" id="cfg_includeoriginal" value="manual" />不加入';
		} else {
			data['includeoriginal'] = '<input type="radio" checked name="cfg_includeoriginal" id="cfg_includeoriginal" value="automatic" />加入<input type="radio" name="cfg_includeoriginal" id="cfg_includeoriginal" value="manual" />不加入';
		}
		if (this.get_profile_content.defaulteditor == "text") {
			data['defaulteditor'] = '<input type="radio"  name="cfg_defaulteditor" id="cfg_defaulteditor" value="html" />HTML编辑（推荐）<input type="radio" checked name="cfg_defaulteditor" id="cfg_defaulteditor" value="text" />文本编辑';
		} else {
			data['defaulteditor'] = '<input type="radio" checked name="cfg_defaulteditor" id="cfg_defaulteditor" value="html" />HTML编辑（推荐）<input type="radio"  name="cfg_defaulteditor" id="cfg_defaulteditor" value="text" />文本编辑';
		}
		if (this.get_profile_content.pagecount == 10) {
			data['pagecount'] = '<input type="radio" checked name="cfg_pagecount" id="cfg_pagecount" value=10 />10<input type="radio" name="cfg_pagecount" id="cfg_pagecount" value=20 />20（推荐）<input type="radio" name="cfg_pagecount" id="cfg_pagecount" value=50 />50<input type="radio" name="cfg_pagecount" id="cfg_pagecount" value=100 />100';
		} else if (this.get_profile_content.pagecount == 20) {
			data['pagecount'] = '<input type="radio" name="cfg_pagecount" id="cfg_pagecount" value=10 />10<input type="radio" checked name="cfg_pagecount" id="cfg_pagecount" value=20 />20（推荐）<input type="radio" name="cfg_pagecount" id="cfg_pagecount" value=50 />50<input type="radio" name="cfg_pagecount" id="cfg_pagecount" value=100 />100';
		} else if (this.get_profile_content.pagecount == 50) {
			data['pagecount'] = '<input type="radio" name="cfg_pagecount" id="cfg_pagecount" value=10 />10<input type="radio" name="cfg_pagecount" id="cfg_pagecount" value=20 />20（推荐）<input type="radio" checked name="cfg_pagecount" id="cfg_pagecount" value=50 />50<input type="radio" name="cfg_pagecount" id="cfg_pagecount" value=100 />100';
		}else if (this.get_profile_content.pagecount == 100) {
			data['pagecount'] = '<input type="radio" name="cfg_pagecount" id="cfg_pagecount" value=10 />10<input type="radio" name="cfg_pagecount" id="cfg_pagecount" value=20 />20（推荐）<input type="radio"  name="cfg_pagecount" id="cfg_pagecount" value=50 />50<input type="radio" checked name="cfg_pagecount" id="cfg_pagecount" value=100 />100';
		}else {
			data['pagecount'] = '<input type="radio" name="cfg_pagecount" id="cfg_pagecount" value=10 />10<input type="radio"  checked  name="cfg_pagecount" id="cfg_pagecount" value=20 />20（推荐）<input type="radio" name="cfg_pagecount" id="cfg_pagecount" value=50 />50<input type="radio"  name="cfg_pagecount" id="cfg_pagecount" value=100 />100';
		}
		/*
		if (this.get_profile_content.viewheader == "full") {
			data['viewheader'] = '<input type="radio"  name="cfg_viewheader" id="cfg_viewheader" value="brief" />简略（推荐）<input type="radio" checked name="cfg_viewheader" id="cfg_viewheader" value="full" />完全';
		} else {
			data['viewheader'] = '<input type="radio" checked name="cfg_viewheader" id="cfg_viewheader" value="brief" />简略（推荐）<input type="radio"  name="cfg_viewheader" id="cfg_viewheader" value="full" />完全';
		}
		*/
		if (this.get_profile_content.record_retr || typeof this.get_profile_content.record_retr == 'undefined') {
			data['record_retr'] = '<input type="radio" checked name="cfg_record_retr" id="cfg_record_retr" value="true" />开启（推荐）<input type="radio" name="cfg_record_retr" id="cfg_record_retr" value="false" />关闭';
		} else {
			data['record_retr'] = '<input type="radio" name="cfg_record_retr" id="cfg_record_retr" value="true" />开启（推荐）<input type="radio" checked name="cfg_record_retr" id="cfg_record_retr" value="false" />关闭';
		}

		DOM.mailConfiguration.innerHTML = t.evaluate(data);
		if(this.get_profile_content.autosavesendmail && contactLists.length > 450) {
			$('addr_limit_info').show();
		}
		addAjaxHistory("mailCfgParameter","changePanel('mailConfiguration','mailCfgParameter', true)", this.getCfgNameByCfgId("mailCfgParameter"), rsh);
	},
	
	mailCfgSign : function(rsh) {
		profile_get({}, this.mailCfgSignCallBack.bind(this, rsh));
	},
	mailCfgSignCallBack : function(rsh, ret) {
		this.get_profile_content = ret;
		// 初始化lightBox
		// if(!this.lightBox) this.lightBox = new Lightbox();
		var t = new Template(mailCfgSignTemplate);
		var data = new Object();
		if (!this.get_profile_content.image_signature) {
			data['image_signature'] = '<input type="checkbox" name="cfg_image_signature" id="cfg_image_signature" value="false"  />';
		} else {
			data['image_signature'] = '<input type="checkbox" checked name="cfg_image_signature" id="cfg_image_signature" value="true"  />';
		}
		
		if(this.get_profile_content.image_signature_name){
			data['image_path']=SIGN_ROOT + '/' + this.get_profile_content.image_signature_name+'.jpg?'+Math.random();
		}else{
			data['image_path']=MailConst.ALL+'/demo.jpg';
		}
		//data['signature'] = this.get_profile_content.signature;
		DOM.mailConfiguration.innerHTML = t.evaluate(data);
        // initEditor();
		Editor1 = new HTMLEditor(['bold', 'fontselect', 'fontsizeselect', 'forecolor', 'createlink']);
		var __t = setTimeout(function() {
			clearTimeout(__t);
			__t = null;
			Editor1.create('ineditorimage');
		}, 1);
		var _onload = function() {
			var _t = setTimeout(function() {
				clearTimeout(_t);
				_t = null;
				// var _c = Editor1.c().document.body.innerHTML;
				try {
					var _j = Editor1.c() && Editor1.c().document.body && typeof Editor1.c().document.body.innerHTML == 'string';
				} catch(e) {}
				try {
					if (_j) {
						var _ts = setTimeout(function() {
							clearTimeout(_ts);
							_ts = null;
							if(mailCfgClass.get_profile_content.signature) {
								Editor1.setContent(mailCfgClass.get_profile_content.signature);
							} else {
								Editor1.setContent('<br />');
							}
							Editor1.setSelect(Editor1.c().document.body, 0, 0);
						}, 100);
					} else {
						_onload();
					}
				} catch(e) {
					_onload();
				}
			}, 100);
			
		};
		_onload();
		addAjaxHistory("mailCfgSign","changePanel('mailConfiguration','mailCfgSign', true)", this.getCfgNameByCfgId("mailCfgSign"), rsh);
	},
	// 预览签名
	mailSignPreview: function() {
		var _ck = $('cfg_image_signature'), _dm = $('demoimg'), _dm_src = _dm.src, _n_dm = '', _w = 0, _html = '', _ct = Editor1.getContent();
		if(_ck.checked) {
			_n_dm = '<img style="width:'+ _dm.style.width +'" src="'+ _dm_src +'" />';
			_w = '180px';
		}
		_html = '<div style="margin:0 auto;width:570px;background-color:white;height:430px;">'
			+'<div style="height:340px;overflow-y:auto;padding:30px;">'
			+'<table cellspacing=0 cellpadding=0 style="border:none;"><tbody><tr><td style="width:'+ _w +'" valign="top">'+ _n_dm +'</td><td valign="top">'+ _ct +'</td></tr></tbody></table>'
			+'</div>'
			+'<div class="closebt" style="width:100%;height:30px;"><div style="float:right;width:40px;cursor:pointer;"><img style="border:none;" src="'+ MailConst.ALL +'/close.gif" /></div></div>'
			+'</div>';
		lightBox.show({html: _html});
	},
	mailCfgAddresser : function(rsh) {
		profile_get({}, this.mailCfgAddresserCallBack.bind(this, rsh));
	},
	mailCfgAddresserCallBack : function(rsh, ret) {
		this.get_profile_content = ret;
		var t = new Template(mailCfgAddresserTemplate);
		var data = new Object();
		data['fullname'] = this.get_profile_content.fullname;
		data['replyto'] = this.get_profile_content.replyto;

		DOM.mailConfiguration.innerHTML = t.evaluate(data);
		Event.observe($("cfg_fullname"), "keydown", function(event) {
			var key = event.keyCode;
			if (key == 13) {
				mailCfgClass.setMailCfgAddresser();
			}
		});
		Event.observe($("cfg_replyto"), "keydown", function(event) {
			var key = event.keyCode;
			if (key == 13) {
				mailCfgClass.setMailCfgAddresser();
			}
		});
		addAjaxHistory("mailCfgAddresser","changePanel('mailConfiguration','mailCfgAddresser', true)", this.getCfgNameByCfgId("mailCfgAddresser"), rsh);
	},
	mailCfgRevert : function(rsh) {
		profile_get({}, this.mailCfgRevertCallBack.bind(this, rsh));
	},
	mailCfgRevertCallBack : function(rsh, ret) {
		var time = new Date().getTime();

		var syear = new Date(time).getFullYear();
		var smonth = new Date(time).getMonth() + 1;
		var sdate = new Date(time).getDate();

		var c = 90 * 24 * 60 * 60 * 1000;
		var eyear = new Date(time + c).getFullYear();
		var emonth = new Date(time + c).getMonth() + 1;
		var edate = new Date(time + c).getDate();

		this.get_profile_content = ret;
		var t = new Template(mailCfgRevertTemplate);
		var data = new Object();
		if (!this.get_profile_content.autoreplyenable) {
			data['autoreplyenable'] = '<input name="cfg_autoreplyenable" id="cfg_autoreplyenable" type="radio" value="true" />打开<input type="radio" checked name="cfg_autoreplyenable" id="cfg_autoreplyenable" value="false" />关闭';
		} else {
			data['autoreplyenable'] = '<input name="cfg_autoreplyenable" id="cfg_autoreplyenable" checked type="radio" value="true" />打开<input type="radio" name="cfg_autoreplyenable" id="cfg_autoreplyenable" value="false" />关闭';
		}

		if (this.get_profile_content.startyear != ""
				&& this.get_profile_content.startmonth != ""
				&& this.get_profile_content.startdate != "") {
			syear = this.get_profile_content.startyear;
			smonth = this.get_profile_content.startmonth;
			sdate = this.get_profile_content.startdate;
		}

		if (this.get_profile_content.endyear != ""
				&& this.get_profile_content.endmonth != ""
				&& this.get_profile_content.enddate != "") {
			eyear = this.get_profile_content.endyear;
			emonth = this.get_profile_content.endmonth;
			edate = this.get_profile_content.enddate;
		}

		this.startyear = syear;
		this.startmonth = smonth;
		this.startdate = sdate;
		this.endyear = eyear;
		this.endmonth = emonth;
		this.enddate = edate;

		// 邮件自动回复起始日期
		data['startyear'] = '<select id="cfg_startyear" name="cfg_startyear" onchange="mailCfgClass.mailCfgRevertTimeChanged();">';
		for (var i = 0; i < 10; i++) {
			if (syear == (i + 2008)) {
				data['startyear'] += '<option selected>' + (i + 2008)
						+ '</option>';
			} else {
				data['startyear'] += '<option>' + (i + 2008) + '</option>';
			}
		}
		data['startyear'] += '</select>';

		data['startmonth'] = '<select id="cfg_startmonth" name="cfg_startmonth" onchange="mailCfgClass.mailCfgRevertTimeChanged();">';
		for (var i = 0; i < 12; i++) {
			if (smonth == (i + 1)) {
				data['startmonth'] += '<option selected>' + (i + 1)
						+ '</option>';
			} else {
				data['startmonth'] += '<option>' + (i + 1) + '</option>';
			}
		}
		data['startmonth'] += '</select>';

		data['startdate'] = '<select id="cfg_startdate" name="cfg_startdate" onchange="mailCfgClass.mailCfgRevertTimeChanged();">';
		for (var i = 0; i < 31; i++) {
			if (sdate == (i + 1)) {
				data['startdate'] += '<option selected>' + (i + 1)
						+ '</option>';
			} else {
				data['startdate'] += '<option>' + (i + 1) + '</option>';
			}
		}
		data['startdate'] += '</select>';

		// 邮件自动回复结束日期
		data['endyear'] = '<select id="cfg_endyear" name="cfg_endyear" onchange="mailCfgClass.mailCfgRevertTimeChanged();">';
		for (var i = 0; i < 11; i++) {
			if (eyear == (i + 2008)) {
				data['endyear'] += '<option selected>' + (i + 2008)
						+ '</option>';
			} else {
				data['endyear'] += '<option>' + (i + 2008) + '</option>';
			}
		}
		data['endyear'] += '</select>';

		data['endmonth'] = '<select id="cfg_endmonth" name="cfg_endmonth" onchange="mailCfgClass.mailCfgRevertTimeChanged();">';
		for (var i = 0; i < 12; i++) {
			if (emonth == (i + 1)) {
				data['endmonth'] += '<option selected>' + (i + 1) + '</option>';
			} else {
				data['endmonth'] += '<option>' + (i + 1) + '</option>';
			}
		}
		data['endmonth'] += '</select>';

		data['enddate'] = '<select id="cfg_enddate" name="cfg_enddate" onchange="mailCfgClass.mailCfgRevertTimeChanged();">';
		for (var i = 0; i < 31; i++) {
			if (edate == (i + 1)) {
				data['enddate'] += '<option selected>' + (i + 1) + '</option>';
			} else {
				data['enddate'] += '<option>' + (i + 1) + '</option>';
			}
		}
		data['enddate'] += '</select>';

		data['AutoReply'] = this.get_profile_content.AutoReply;
		if (this.get_profile_content.forwardenable == true) {
			data['forwardenable'] = '<input name="cfg_forwardenable" id="cfg_forwardenable" checked type="radio" value="true" />打开<input type="radio" name="cfg_forwardenable" id="cfg_forwardenable" value="false" />关闭';
		}

		else {
			data['forwardenable'] = '<input name="cfg_forwardenable" id="cfg_forwardenable" type="radio" value="true" />打开<input type="radio" checked name="cfg_forwardenable" id="cfg_forwardenable" value="false" />关闭';
		}
		data['forward'] = this.get_profile_content.forward;
		if (this.get_profile_content.reserveforward == true) {
			data['reserveforward'] = '<input type="radio" checked name="cfg_reserveforward" id="cfg_reserveforward" value="true" />保留<input type="radio" name="cfg_reserveforward" id="cfg_reserveforward" value="false" /> 不保留';
		} else {
			data['reserveforward'] = '<input type="radio" name="cfg_reserveforward" id="cfg_reserveforward" value="true" />保留<input type="radio" checked name="cfg_reserveforward" id="cfg_reserveforward" value="false" /> 不保留';
		}

		DOM.mailConfiguration.innerHTML = t.evaluate(data);
		addAjaxHistory("mailCfgRevert","changePanel('mailConfiguration','mailCfgRevert', true)", this.getCfgNameByCfgId("mailCfgRevert"), rsh);
	},

	mailCfgRevertTimeChanged : function() {
		var sy = $A($('cfg_startyear').options).find(function(o) {
			if (o.selected) {
				return o;
			}
		}).innerHTML;
		sy = (sy && sy != null) ? sy : this.startyear;

		var sm = $A($('cfg_startmonth').options).find(function(o) {
			if (o.selected) {
				return o;
			}
		}).innerHTML;
		sm = (sm && sm != null) ? sm : this.startmonth;

		var sd = $A($('cfg_startdate').options).find(function(o) {
			if (o.selected) {
				return o;
			}
		}).innerHTML;
		sd = (sd && sd != null) ? sd : this.startdate;

		var ey = $A($('cfg_endyear').options).find(function(o) {
			if (o.selected) {
				return o;
			}
		}).innerHTML;
		ey = (ey && ey != null) ? ey : this.endyear;

		var em = $A($('cfg_endmonth').options).find(function(o) {
			if (o.selected) {
				return o;
			}
		}).innerHTML;
		em = (em && em != null) ? em : this.endmonth;

		var ed = $A($('cfg_enddate').options).find(function(o) {
			if (o.selected) {
				return o;
			}
		}).innerHTML;
		ed = (ed && ed != null) ? ed : this.enddate;

		this.startyear = sy;
		this.startmonth = sm;
		this.startdate = sd;
		
		var beforeTime = (new Date(ey, em, ed).getTime() < (new Date(sy, sm, sd).getTime() + 24 * 60 * 60 * 1000));
		var afterTime = ((new Date(ey, em, ed).getTime() - new Date(sy, sm, sd).getTime()) > 90 * 24 * 60 * 60 * 1000);

		if (afterTime || beforeTime) {
			if(afterTime) {
				var newTime = new Date(new Date(sy, sm, sd).getTime() + 90 * 24 * 60 * 60 * 1000);
				$('cfg_time_period').update(' （时间范围超出了限制，系统默认为您设置成了90天） ');
			} else {
				var newTime = new Date(new Date(sy, sm, sd).getTime() + 24 * 60 * 60 * 1000);
				$('cfg_time_period').update(' （结束时间不能小于起始时间，系统默认为您设置成了1天） ');
			}
			this.endyear = newTime.getFullYear();
			this.endmonth = newTime.getMonth();
			this.enddate = newTime.getDate();

			for (var i = 0; i < $('cfg_endyear').options.length; i++) {
				if ($('cfg_endyear').options[i].selected) {
					$('cfg_endyear').options[i].selected = !$('cfg_endyear').options[i].selected;
				}
				if ($('cfg_endyear').options[i].innerHTML == this.endyear) {
					$('cfg_endyear').options[i].selected = !$('cfg_endyear').options[i].selected;
				}
			}

			for (var i = 0; i < $('cfg_endmonth').options.length; i++) {
				if ($('cfg_endmonth').options[i].selected) {
					$('cfg_endmonth').options[i].selected = !$('cfg_endmonth').options[i].selected;
				}
				if ($('cfg_endmonth').options[i].innerHTML == this.endmonth) {
					$('cfg_endmonth').options[i].selected = !$('cfg_endmonth').options[i].selected;
				}
			}

			for (var i = 0; i < $('cfg_enddate').options.length; i++) {
				if ($('cfg_enddate').options[i].selected) {
					$('cfg_enddate').options[i].selected = !$('cfg_enddate').options[i].selected;
				}
				if ($('cfg_enddate').options[i].innerHTML == this.enddate) {
					$('cfg_enddate').options[i].selected = !$('cfg_enddate').options[i].selected;
				}
			}
			$('cfg_time_period').show();
		} else {
			this.endyear = ey;
			this.endmonth = em;
			this.enddate = ed;
			$('cfg_time_period').hide();
		}
	},
	
	
	
	//白名单设置 (quzhi )
	mailWhiteList:function(rsh){
		this.mailWhiteListCallBack(rsh, whiteLists);
	},
	
	mailWhiteListCallBack:function(rsh, ret) {
		// this.get_profile_content=ret;
		// dateWhiteLists = ret.wlist;
		var t = new Template(mailWhiteListTemplate); 
		var t2 = new Template(mailWhiteListTemplate2);
		var data = {};
		// if(this.get_profile_content.flag=='2'){
		if(whiteOnly == 2) {
			data['flag']="2";
			data['check']="checked";
		} else {
			data['flag']="1";
		}
		var htmlString = [];
		htmlString.push(t.evaluate(data));
		// var htmlString = t.evaluate(data);
		
		whiteLists.each(function(item, index) {
			var data2 = {};
		  	data2['id'] = index;
		  	data2['name'] = item.email;
		  	data2['operations'] = ['<a href="javascript:;" hidefocus="true" onclick="mailCfgClass.showWBList(',
		                           index,
								   ')">[修改]</a>&nbsp;&nbsp;<a href="javascript:;" hidefocus="true" onclick="mailCfgClass.setMailWhiteDelFilter(\'',
					               item.email,
								   '\')">[删除]</a>'].join('');
          	data2['operations2'] = ['<a href="javascript:;" hidefocus="true" onclick="mailCfgClass.setMailWhiteUpFilter(\'',
		                            item.email,
									'\',',
									index,
									')">[确认修改]</a>&nbsp;<a href="javascript:;" hidefocus="true" onclick="mailCfgClass.hideWBList(',
									index,
									')">[取消修改]</a>&nbsp;<a href="javascript:;" hidefocus="true" onclick="mailCfgClass.setMailWhiteDelFilter(\'',
					             	item.email,
									'\')">[删除]</a>'].join('');
		 	htmlString.push(t2.evaluate(data2));
		});
		
		htmlString.push('</table></div></div>');   
        DOM.mailConfiguration.innerHTML = htmlString.join('');
		
		new AddressFilter('white_textarea', DOM.mailConfiguration, contactLists);
		
		addAjaxHistory("mailWhiteList","changePanel('mailConfiguration','mailWhiteList', true)", this.getCfgNameByCfgId("mailWhiteList"), rsh);
	},
	
	mailCheckWhiteOnly: function(el) {
		if(el.checked){
			el.checked = false;
			_dialog.confirm({info: '您的邮箱将只能接收您的白名单列表中的邮箱地址发来的邮件，您确定此操作吗？', click: function() {
				white_only({whiteonly: 2}, function(ret) {
					if(ret.status == true) whiteOnly = ret.msg;
					var _info = $('set_only_white');
					_info.style.visibility = 'visible';
					_info.innerHTML = '设置成功！';
					var _t = setTimeout(function() {
						clearTimeout(_t);
						_t = null;
						_info.style.visibility = 'hidden';
					}, 3000);
				});
				el.checked = true;
			}});
		} else {
			el.checked = false;
			white_only({whiteonly: 1}, function(ret) {
				if(ret.status == true) whiteOnly = ret.msg;
				var _info = $('set_only_white');
				_info.style.visibility = 'visible';
				_info.innerHTML = '取消成功！';
				var _t = setTimeout(function() {
					clearTimeout(_t);
					_t = null;
					_info.style.visibility = 'hidden';
				}, 3000);
			});
		}
	},

	mailCfgRefuse : function(rsh) {
		this.mailCfgRefuseCallBack(rsh, blackLists);
	},
	mailCfgRefuseCallBack : function(rsh, ret) {
		var t = new Template(mailBlackListTemplate); 
		var t2 = new Template(mailBlackListTemplate2);
		var data = {};
		var htmlString = [];
		htmlString.push(t.evaluate(data));
		// var htmlString = t.evaluate(data);
		
		blackLists.each(function(item, index) {
			var data2 = {};
		  	data2['id'] = item.id;
		  	data2['name'] = item.email;
		  	data2['operations'] = ['&nbsp;  <a href="javascript:;" hidefocus="true" onclick="mailCfgClass.mailCfgBlackDel(\'',
					               item.email,
								   '\')">[删除]</a>'].join('');
		 	htmlString.push(t2.evaluate(data2));
		});
		
		htmlString.push('</table></div></div>');   
        DOM.mailConfiguration.innerHTML = htmlString.join('');
		/*
         if (this.isDisplayPrompt) {
			 $("whileerror_info").style.display = "";
		} else {
			$("whileerror_info").style.display = "none";
		}
		*/
		new AddressFilter('black_textarea', DOM.mailConfiguration, contactLists);
		addAjaxHistory("mailCfgRefuse","changePanel('mailConfiguration','mailCfgRefuse', true)", this.getCfgNameByCfgId("mailCfgRefuse"), rsh);
	},
	
	mailCfgBlackDel: function(email) {
		del_blacklist({email: email}, function(ret) {
			var _black_list = [];
			blackLists.each(function(item) {
				if(item.email != email) _black_list.push(item);
			});
			blackLists = _black_list;
			this.mailCfgRefuse();
		}.bind(this));
	},
	
	mailCfgFilter : function(rsh) {
		profile_get({}, this.mailCfgFilterCallBack.bind(this, rsh));
	},
	mailCfgFilterCallBack : function(rsh, ret) {
		try {
			DOM.newFolderList.hide();
			DOM.mailConfiguration.show();
		} catch(e) {}
		this.get_profile_content = ret;
		this.showCfgFilter.clear();
		var t = new Template(mailCfgFilterTemplate);
		var data = new Object();
		try {
			data['filter0'] = this.filterData(this.get_profile_content['filter.0'],
				"filter.0");
			data['filter1'] = this.filterData(this.get_profile_content['filter.1'],
				"filter.1");
			data['filter2'] = this.filterData(this.get_profile_content['filter.2'],
				"filter.2");
			data['filter3'] = this.filterData(this.get_profile_content['filter.3'],
				"filter.3");
			data['filter4'] = this.filterData(this.get_profile_content['filter.4'],
				"filter.4");
			data['filter5'] = this.filterData(this.get_profile_content['filter.5'],
				"filter.5");
			data['filter6'] = this.filterData(this.get_profile_content['filter.6'],
				"filter.6");
			data['filter7'] = this.filterData(this.get_profile_content['filter.7'],
				"filter.7");
			data['filter8'] = this.filterData(this.get_profile_content['filter.8'],
				"filter.8");
			data['filter9'] = this.filterData(this.get_profile_content['filter.9'],
				"filter.9");
		} catch(e) {}
		data['folderlist'] = "";
		for (var i = 0; i < FoldersData.folders.length; i++) {
			if (FoldersData.folders[i].folder_id == 2 || FoldersData.folders[i].folder_id == 3) {
				continue;
			}
			data['folderlist'] += '<option value="'
					+ FoldersData.folders[i].folder_id + '">'
					+ FoldersData.folders[i].name + '</option>';
		}

		var j = 0;
		for (var i = 0; i < 10; i++) {
			if (data['filter' + i] != "") {
				this.showCfgFilter[j++] = "filter." + i;
			}
		}
		DOM.mailConfiguration.innerHTML = t.evaluate(data);
		if (this.isDisplayPrompt) {
			$("prompt_info").style.display = "";
		} else {
			$("prompt_info").style.display = "none";
		}
		addAjaxHistory("mailCfgFilter","changePanel('mailConfiguration','mailCfgFilter', true)", this.getCfgNameByCfgId("mailCfgFilter"), rsh);
	},
	mailCfgFilter2 : function(rsh) {
		profile_get({}, this.mailCfgFilter2CallBack.bind(this, rsh));
	},
	mailCfgFilter2CallBack : function(rsh, ret) {
		this.get_profile_content = ret;
		var t = new Template(mailCfgFilter2Template);
		var data = new Object();
		try {
			data['filter0'] = this.filterData2(
				this.get_profile_content['filter.0'], "filter.0");
			data['filter1'] = this.filterData2(
				this.get_profile_content['filter.1'], "filter.1");
			data['filter2'] = this.filterData2(
				this.get_profile_content['filter.2'], "filter.2");
			data['filter3'] = this.filterData2(
				this.get_profile_content['filter.3'], "filter.3");
			data['filter4'] = this.filterData2(
				this.get_profile_content['filter.4'], "filter.4");
			data['filter5'] = this.filterData2(
				this.get_profile_content['filter.5'], "filter.5");
			data['filter6'] = this.filterData2(
				this.get_profile_content['filter.6'], "filter.6");
			data['filter7'] = this.filterData2(
				this.get_profile_content['filter.7'], "filter.7");
			data['filter8'] = this.filterData2(
				this.get_profile_content['filter.8'], "filter.8");
			data['filter9'] = this.filterData2(
				this.get_profile_content['filter.9'], "filter.9");
		} catch(e) {}
		data['folderlist'] = "";
		for (var i = 0; i < FoldersData.folders.length; i++) {
			if (FoldersData.folders[i].folder_id == 2 || FoldersData.folders[i].folder_id == 3) {
				continue;
			}
			data['folderlist'] += '<option value="'
					+ FoldersData.folders[i].folder_id + '">'
					+ FoldersData.folders[i].name + '</option>';
		}
		DOM.mailConfiguration.innerHTML = t.evaluate(data);
		addAjaxHistory("mailCfgFilter2","changePanel('mailConfiguration','mailCfgFilter2', true)", this.getCfgNameByCfgId("mailCfgFilter2"), rsh);
	},
	filterData2 : function(fdata, checknum) {
		if(!fdata || typeof fdata == 'undefined') return '';
		var dataArray = fdata.split(",");
		if(dataArray.length != 5) {
			fdata = "0,,,0,";
			dataArray = fdata.split(",");
		}
		var par1 = dataArray[0];
		var par2 = dataArray[1];
		var par3 = dataArray[2];
		var par4 = dataArray[3];
		var par5 = dataArray[4];
		if(par5 == "''") par5 = '';
		if(par5 == '') {
			par5 = '收件箱';
		} else if (typeof parseInt(par5) == 'number') {
			par5 = mailList.getFolderItem(dataArray[4]).name;
		}
		if (par2 == 0) {
			par2 = "标题";
		} else if (par2 == 1) {
			par2 = "发件人";
		} else {
			par2 = "邮件头";
		}

		if (par4 == 0) {
			par4 = "包含";
		} else if (par4 == 1) {
			par4 = "不包含";
		} else if (par4 == 2) {
			par4 = "等于";
		} else {
			par4 = "不等于";
		}
		if (par3.strip() != "") {
			if (this.showCfgFilter.length == 1) {
				if (par1 == 1) {
					return '<tr><td><input type="checkbox" name="' + checknum
							+ '" checked value=1 /></td><td>' + par2 + par4
							+ par3 + '</td><td>移到 ' + par5
							+ '</td><td></td></tr>';
				} else {
					return '<tr><td><input type="checkbox" name="' + checknum
							+ '" value=0 /></td><td>' + par2 + par4 + par3
							+ '</td><td>移到 ' + par5 + '</td><td></td></tr>';
				}
			}
			if (checknum == this.showCfgFilter[0]) {
				if (par1 == 1) {
					return '<tr><td><input type="checkbox" name="'
							+ checknum
							+ '" checked value=1 /></td><td>'
							+ par2
							+ par4
							+ par3
							+ '</td><td>移到 '
							+ par5
							+ '</td><td><a href="javascript:;" hidefocus="true" onclick="mailCfgClass.moveDownCfgFilter(\''
							+ checknum + '\')">下移</a></td></tr>';
				} else {
					return '<tr><td><input type="checkbox" name="'
							+ checknum
							+ '" value=0 /></td><td>'
							+ par2
							+ par4
							+ par3
							+ '</td><td>移到 '
							+ par5
							+ '</td><td><a href="javascript:;" hidefocus="true" onclick="mailCfgClass.moveDownCfgFilter(\''
							+ checknum + '\')">下移</a></td></tr>';
				}
			} else if (checknum == this.showCfgFilter[this.showCfgFilter.length
					- 1]) {
				if (par1 == 1) {
					return '<tr><td><input type="checkbox" name="'
							+ checknum
							+ '" checked value=1 /></td><td>'
							+ par2
							+ par4
							+ par3
							+ '</td><td>移到 '
							+ par5
							+ '</td><td><a href="javascript:;" hidefocus="true" onclick="mailCfgClass.moveUpCfgFilter(\''
							+ checknum + '\')">上移</a>　</td></tr>';
				} else {
					return '<tr><td><input type="checkbox" name="'
							+ checknum
							+ '" value=0 /></td><td>'
							+ par2
							+ par4
							+ par3
							+ '</td><td>移到 '
							+ par5
							+ '</td><td><a href="javascript:;" hidefocus="true" onclick="mailCfgClass.moveUpCfgFilter(\''
							+ checknum + '\')">上移</a>　</td></tr>';
				}
			} else {
				if (par1 == 1) {
					return '<tr><td><input type="checkbox" name="'
							+ checknum
							+ '" checked value=1 /></td><td>'
							+ par2
							+ par4
							+ par3
							+ '</td><td>移到 '
							+ par5
							+ '</td><td><a href="javascript:;" hidefocus="true" onclick="mailCfgClass.moveUpCfgFilter(\''
							+ checknum
							+ '\')">上移</a>　<a href="javascript:;" hidefocus="true" onclick="mailCfgClass.moveDownCfgFilter(\''
							+ checknum + '\')">下移</a></td></tr>';
				} else {
					return '<tr><td><input type="checkbox" name="'
							+ checknum
							+ '" value=0 /></td><td>'
							+ par2
							+ par4
							+ par3
							+ '</td><td>移到 '
							+ par5
							+ '</td><td><a href="javascript:;" hidefocus="true" onclick="mailCfgClass.moveUpCfgFilter(\''
							+ checknum
							+ '\')">上移</a>　<a href="javascript:;" hidefocus="true" onclick="mailCfgClass.moveDownCfgFilter(\''
							+ checknum + '\')">下移</a></td></tr>';
				}
			}
		} else {
			return "";
		}
	},
	moveUpCfgFilter : function(filtername) {
		var params = {};
		var par1, par2;
		for (var i = this.showCfgFilter.length - 1; i >= 0; i--) {
			if (this.showCfgFilter[i] == filtername) {
				par1 = this.showCfgFilter[i];
				par2 = this.showCfgFilter[i - 1];
			}
		}
		params[par1] = this.get_profile_content[par2];
		params[par2] = this.get_profile_content[par1];
		profile_set(params, this.setMailCfgFilterCallBack.bind(this));
	},
	moveDownCfgFilter : function(filtername) {
		var params = {};
		var par1, par2;
		for (var i = 0; i < this.showCfgFilter.length; i++) {
			if (this.showCfgFilter[i] == filtername) {
				par1 = this.showCfgFilter[i];
				par2 = this.showCfgFilter[i + 1];
			}
		}
		params[par1] = this.get_profile_content[par2];
		params[par2] = this.get_profile_content[par1];
		profile_set(params, this.setMailCfgFilterCallBack.bind(this));
	},

	filterData : function(fdata, checknum) {
		if(!fdata || typeof fdata == 'undefined') return '';
		var dataArray = fdata.split(",");
		if(dataArray.length != 5) {
			fdata = "0,,,0,''";
			dataArray = fdata.split(",");
		}
		var par1 = dataArray[0];
		var par2 = dataArray[1];
		var par3 = dataArray[2];
		var par4 = dataArray[3];
		var par5 = dataArray[4];
		if(par5 == "''") par5 = '';
		if(par5 == '') {
			par5 = '收件箱';
		} else if (typeof parseInt(par5) == 'number') {
			par5 = mailList.getFolderItem(dataArray[4]).name;
		}
		if (par2 == 0) {
			par2 = "标题";
		} else if (par2 == 1) {
			par2 = "发件人";
		} else {
			par2 = "邮件头";
		}

		if (par4 == 0) {
			par4 = "包含";
		} else if (par4 == 1) {
			par4 = "不包含";
		} else if (par4 == 2) {
			par4 = "等于";
		} else {
			par4 = "不等于";
		}

		if (par3.strip() != "") {
			if (par1 == 1) {
				return '<tr><td><input type="checkbox" name="'
						+ checknum
						+ '" checked value=1 /></td><td>'
						+ par2
						+ par4
						+ par3
						+ '</td><td>移到 '
						+ par5
						+ '</td><td><a href="javascript:;" hidefocus="true" onclick="mailCfgClass.setMailCfgUpFilter(\''
						+ checknum
						+ '\');">修改</a>　<a href="javascript:;" hidefocus="true" onclick="mailCfgClass.setMailCfgDelFilter(\''
						+ checknum + '\');">删除</a></td></tr>';
			} else {
				return '<tr><td><input type="checkbox" name="'
						+ checknum
						+ '" value=0 /></td><td>'
						+ par2
						+ par4
						+ par3
						+ '</td><td>移到 '
						+ par5
						+ '</td><td><a href="javascript:;" hidefocus="true" onclick="mailCfgClass.setMailCfgUpFilter(\''
						+ checknum
						+ '\');">修改</a>　<a href="javascript:;" hidefocus="true" onclick="mailCfgClass.setMailCfgDelFilter(\''
						+ checknum + '\');">删除</a></td></tr>';
			}
		} else {
			return "";
		}
	},

	setMailCfgParameter : function() {
		if (global_flag) {
			return;
		}
		this.cfgSuccPrompt = true;
		var cf = $('cfg_parameter');
		var params = {
			// autosave : this.getRadioCheckedValue(cf.cfg_autosave),
			autosavesendmail : this.getRadioCheckedValue(cf.cfg_autosavesendmail),
			autosavewritemail : this.getRadioCheckedValue(cf.cfg_autosavewritemail),
			isconference: this.getRadioCheckedValue(cf.cfg_isconference),
			showsenderaddr : this.getRadioCheckedValue(cf.cfg_showsenderaddr),
			replytoken : this.getRadioCheckedValue(cf.cfg_replytoken),
			includeoriginal : this.getRadioCheckedValue(cf.cfg_includeoriginal),
			defaulteditor : this.getRadioCheckedValue(cf.cfg_defaulteditor),
			pagecount : this.getRadioCheckedValue(cf.cfg_pagecount),
			// viewheader : this.getRadioCheckedValue(cf.cfg_viewheader)
			record_retr: this.getRadioCheckedValue(cf.cfg_record_retr)
		};
		profile_set(params, this.setMailCfgCallBack.bind(this));
	},

	setMailCfgCallBack : function(ret) {
		if (ret.is_success) {
			try {
				mailList.clearListCache();
			} catch(e) {}
			try {
				mailConference.clearListCache();
			} catch(e) {}
			this.initMailCfg();
		}
	},

	setMailCfgFilterCallBack : function(ret) {
		// alert(ret.is_success);
		if (ret.is_success) {
			this.isDisplayPrompt = true;
			this.initMailCfg(false, this.mailCfgFilterCallBack);
		}
	},
	
	setMailCfgSignImg: function(){
		this.cfgSuccPrompt = true;
		var tmp_image_sign_name = "";
		if (mailCfgClass.getProfileContent().image_signature_name) {
			tmp_image_sign_name = mailCfgClass.getProfileContent().image_signature_name;
		}
		else {
			tmp_image_sign_name = image_signature_name;
		}
		
		var params = {
			image_signature: $('cfg_image_signature').checked,
			image_signature_name: tmp_image_sign_name
		};
		profile_set(params, this.setMailCfgSignImgCallBack.bind(this));
	},
	
	setMailCfgSignImgCallBack:function(ret){
		if(ret.success){
			return;
		}
		
	},
    

	setMailCfgSign: function(){
		if (global_flag) {
			return;
		}
		var textSign = Editor1.getContent();

		this.cfgSuccPrompt = true;

		var params = {
			image_signature: $('cfg_image_signature').checked,
			signature: textSign
		};
		
		profile_set(params, this.setMailCfgCallBack.bind(this));
	},
	
	/*
	setMailCfgAvatar : function() {
        var tmp = image_avatar.join(",");
		var params = {};
		this.cfgSuccPrompt = false;
		this.signPrompt = true;
		if (image_avatar_use != "") {
			if (image_avatar_use == "demo1.jpg" || image_avatar_use == "mail_red.jpg" || image_avatar_use == "mail_yellow.jpg" || image_avatar_use == "mail_blue.jpg" || image_avatar_use == "mail_green.jpg" || image_avatar_use == "mail_grey.jpg") {
				$('user_face').src = MailConst.IMG + '/' + image_avatar_use;
				params['image_avatar_use'] = image_avatar_use;
			}
			else {
				$('user_face').src = SIGN_ROOT + '/' + image_avatar_use + '.jpg?'+Math.random();
				params['image_avatar_use'] = image_avatar_use;
				params['image_avatar'] = tmp;
			}
		}else{
			params['image_avatar_use'] = "demo1.jpg";
		}
		profile_set(params, this.setMailCfgCallBack.bind(this));

	},
	*/
	
	setMailCfgAddresser : function() {
		if (global_flag) {
			return;
		}
		this.cfgSuccPrompt = true;
		var fn = toTrimDBC($("cfg_fullname").value.strip());
		var rt = toTrimDBC($("cfg_replyto").value.strip());
		if (rt != "") {
			if (!IsEmail(rt)) {
				return;
			}
		}
		var params = {
			fullname : fn,
			replyto : rt
		};
		profile_set(params, this.setMailCfgCallBack.bind(this));
	},

	setMailCfgRevert : function() {
		if (global_flag) {
			return;
		}
		this.cfgSuccPrompt = true;
		var cfg_forward_addr = toTrimDBC($('cfg_forward').value.strip())
				.toLowerCase();
		if (cfg_forward_addr != "" && !IsEmail(cfg_forward_addr)) {
			return;
		}
		if (cfg_forward_addr.include(UserSohuID)) {
			// alert("不能自动转发给自己");
			_dialog.alert({info: '不能自动转发给自己'});
			return;
		}
		var params = {
			autoreplyenable : this
					.getRadioCheckedValue($("cfg_revert").cfg_autoreplyenable),
			startyear : this.startyear,
			startmonth : this.startmonth,
			startdate : this.startdate,
			endyear : this.endyear,
			endmonth : this.endmonth,
			enddate : this.enddate,
			AutoReply : $('cfg_revert').cfg_AutoReply.value,
			forwardenable : this
					.getRadioCheckedValue($("cfg_revert").cfg_forwardenable),
			forward : cfg_forward_addr,
			reserveforward : this
					.getRadioCheckedValue($("cfg_revert").cfg_reserveforward)
		};
		profile_set(params, this.setMailCfgCallBack.bind(this));
	},

	setMailCfgRefuse : function() {
		// this.cfgSuccPrompt = true;
		var _blist = arguments[0] ? arguments[0].strip() : $('black_textarea').value.strip();
		var _callback = arguments[1];
		if(_blist == '') {
			_dialog.alert({info: '添加的邮件地址不能为空'});
			return;
		}
		if(_blist.include('<') && _blist.include('>')) {
			var _s = _blist.indexOf('<');
			var _e = _blist.indexOf('>');
			_blist = _blist.substring(_s+1, _e);
			if(!writemail.getCheckEmailAddress(_blist)) {
				return;
			}
		}
		if(!IsEmail(_blist)) return;
		var params = {
			blocklist : _blist
			// reserveblocked : this.getRadioCheckedValue($("cfg_refuse").cfg_reserveblocked)
		};
		// var _blista = _blist.split(',');
		
		// 生成两个临时的hash表：whitelists contactlists
		var _white_hash = {};
		var _black_hash = {};
		var _contact_hash = {};
		whiteLists.each(function(item) {
			_white_hash[item.email] = item.nickname;
		});
		blackLists.each(function(item) {
			_black_hash[item.email] = item.nickname;
		});
		contactLists.each(function(item) {
			_contact_hash[item.email] = item.nickname;
		});
		if(typeof _black_hash[_blist] != 'undefined') {
			_dialog.alert({info: '黑名单中已经存在了当前地址！'});
			return;
		}
		var confunc_ref = function() {
			mod_blacklist(params, function(ret) {
				if(ret.status == true) {
					if (Object.isArray(ret.msg)) {
						blackLists = blackLists.concat(ret.msg);
					} else {
						blackLists.push(ret.msg);
					}
					this.mailCfgRefuse();
				}
			}.bind(this));
			if(_callback) _callback();
		}.bind(this); 
		var self = this;
		if(typeof _white_hash[_blist] != 'undefined') {
			var _t1 = setTimeout(function() {
				clearTimeout(_t1);
				_t1 = null;
				_dialog.confirm({info: '该地址在白名单中，添加到黑名单会将其从白名单中删除，是否要继续？', click: function() {
					confunc_ref();
					// self.setMailCfgCallBack({is_success: true});
					var _white_lists = [];
					whiteLists.each(function(item) {
						if(item.email != _blist) _white_lists.push(item);
					});
					whiteLists = _white_lists;
					if(typeof _contact_hash[_blist] != 'undefined') {
						mailAddressClass.deleteContact(_blist, true);
					}
				}});
			}, 10)
			
			return;
		}
		if(typeof _contact_hash[_blist] != 'undefined') {
			var _t2 = setTimeout(function() {
				clearTimeout(_t2);
				_t2 = null;
				_dialog.confirm({info: '该地址在地址簿中，添加到黑名单会将其从地址簿中删除，是否要继续？', click: function() {
					confunc_ref();
					mailAddressClass.deleteContact(_blist, true);
				}});
			}, 10);
			return;
		}
		confunc_ref();
	},

	setMailCfgFilter : function() {
		if (global_flag) {
			return;
		}
		var params = {
			"filter.0" : this.rtCheckedData(
					this.get_profile_content['filter.0'], "filter.0"),
			"filter.1" : this.rtCheckedData(
					this.get_profile_content['filter.1'], "filter.1"),
			"filter.2" : this.rtCheckedData(
					this.get_profile_content['filter.2'], "filter.2"),
			"filter.3" : this.rtCheckedData(
					this.get_profile_content['filter.3'], "filter.3"),
			"filter.4" : this.rtCheckedData(
					this.get_profile_content['filter.4'], "filter.4"),
			"filter.5" : this.rtCheckedData(
					this.get_profile_content['filter.5'], "filter.5"),
			"filter.6" : this.rtCheckedData(
					this.get_profile_content['filter.6'], "filter.6"),
			"filter.7" : this.rtCheckedData(
					this.get_profile_content['filter.7'], "filter.7"),
			"filter.8" : this.rtCheckedData(
					this.get_profile_content['filter.8'], "filter.8"),
			"filter.9" : this.rtCheckedData(
					this.get_profile_content['filter.9'], "filter.9")
		};
		profile_set(params, this.setMailCfgFilterCallBack.bind(this));
	},

	setMailCfgAddFilter : function() {
		if (global_flag) {
			return;
		}
		var params = {};
		if (this.updateCfgFilterName != "") {
			var filter = this.updateCfgFilterName;
			params[filter] = this.setMailCfgAddFilterValue();
			this.updateCfgFilterName = "";
		} else {
			if (this.showCfgFilter.length != 10) {
				for (var i = 0; i < 10; i++) {
					if (this.showCfgFilter.indexOf("filter." + i) == -1) {
						params["filter." + i] = this.setMailCfgAddFilterValue();
						break;
					}
				}
			} else {
				params["filter.9"] = this.setMailCfgAddFilterValue();
			}
		}
		profile_set(params, this.setMailCfgFilterCallBack.bind(this));
	},
	
	
	//白名单设置（quzhi 回调函数暂时不做修改）
	setMailCfgAddWhite : function() {
		if (global_flag) {
			return;
		}
		var _email = $('white_textarea').value;
		if(_email.strip() == UserSohuID) {
			_dialog.alert({info: '不能把自己添加到白名单'});
			return;
		}
		
		if(_email == '') {
			_dialog.alert({info: '添加的邮件地址不能为空'});
			return;
		}
		
		var _field = false;
		if(_email.startsWith('@')) {
			var _new_email = 'xxx' + _email;
			var regm = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
			if (!_new_email.match(regm)) {
				_dialog.alert({info: '请输入正确的域地址，例如：@' + localPostfix});
				return;
			} else {
				_field = true;
			}
		}
		
		if(_email.include('<') && _email.include('>')) {
			var _s = _email.indexOf('<');
			var _e = _email.indexOf('>');
			_email = _email.substring(_s+1, _e);
		}
		
		if(!_field && !IsEmail(_email)) return;
		
		var _flag_white = false;
		whiteLists.each(function(item) {
			if(item.email == _email.strip()) _flag_white = true;
		});
		if(_flag_white) {
			_dialog.alert({info: '白名单中已经存在了当前地址！'});
			return;
		}
		
		var _flag = false;
		var _black_lists = [];
		blackLists.each(function(item) {
			if (item.email == _email.strip()) {
				_flag = item.email;
			} else {
				_black_lists.push(item);
			}
		});
		var confunc_addw = function() {
			var params = {email: _email};
			// whitelist_post(params, this.setMailWhiteListCallBack.bind(this));
			add_whitelist(params, this.setMailWhiteListCallBack.bind(this), this.setMailWhiteListFailureCallBack.bind(this));
		}.bind(this);
		if(_flag) {
			_dialog.confirm({
				info: '该地址在黑名单中，添加到白名单将会把他从黑名单中删除！',
				click: function(){
					confunc_addw();
					blackLists = _black_lists;
				}
			});
			return;
		}
		confunc_addw();
	},
	
	setMailWhiteListCallBack:function(ret) {
		if(ret.status == true) {
			this.isDisplayPrompt = true;
		  	this.isWBDisplayPrompt=false;
			whiteLists.push(ret.msg);
			this.mailWhiteList();
		} else if(ret.msg) {
			_dialog.alert({info: ret.msg});
			return;
		} else {
			this.setMailWhiteListFailureCallBack();
		}
	},
	
	setMailWhiteListFailureCallBack: function() {
		_dialog.alert({info: '未知错误，请重试！'});
	},
	
	setMailWhiteDelFilter : function(email) {
		var params = {email: email};
		// whitelist_post(params, this.setMailWhiteListCallBack.bind(this));
		del_whitelist(params, function(ret) {
			if(ret.status == true) {
				var _white_list = [];
				whiteLists.each(function(item) {
					if(item.email != ret.msg.email) _white_list.push(item);
				});
				whiteLists = _white_list;
				this.mailWhiteList();
			} else {
				
			}
		}.bind(this));
	},
	
	setMailWhiteUpFilter : function(email,id) {
		var _newemail = $('upName_'+id).value;
		var _flag = false;
		blackLists.each(function(item) {
			if(item.email == _newemail) _flag = true;
		});
		var _flag_white = false;
		whiteLists.each(function(item) {
			if(item.email == _newemail) _flag_white = true;
		});
		if(_flag_white) {
			_dialog.alert({info: '该地址已经存在白名单中了！'});
			return;
		}
		
		var _field = false;
		if(_newemail.startsWith('@')) {
			var _new_email = 'xxx' + _newemail;
			var regm = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
			if (!_new_email.match(regm)) {
				_dialog.alert({info: '请输入正确的域地址，例如：@' + localPostfix});
				return;
			} else {
				_field = true;
			}
		}
		if(!_field && !IsEmail(_newemail)) return;
		
		var confunc_white = function() {
			var params = {email: email, emailnew: _newemail};
			mod_whitelist(params, function(email, ret) {
				if(ret.status == true) {
					whiteLists.each(function(item) {
						if(item.email == email) item.email = ret.msg.email;
					});
					this.mailWhiteList();
				} else {
				
				}
			}.bind(this, email));
		}.bind(this);
		if(_flag) {
			_dialog.confirm({info: '该地址在黑名单中，添加到白名单将会把他从黑名单中删除！', click: function() {
				var _black_list = [];
				blackLists.each(function(item) {
					if(item.email != _newemail) _black_list.push(item);
				});
				blackLists = _black_list;
				confunc_white();
			}});
			return;
		}
		confunc_white();
	},

	setMailCfgDelFilter : function(filter) {
		var params = {};
		params[filter] = "0,,,0,''";
		profile_set(params, this.setMailCfgFilterCallBack.bind(this));
	},

	setMailCfgUpFilter : function(filter) {
		this.updateCfgFilterName = filter;
		var filter = this.get_profile_content[filter].split(",");
		var par2 = $("cfg_filter").cfg_filter_par2;
		this.resetSelectedOption(par2, filter[1]);
		$("cfg_filter").cfg_filter_par3.value = filter[2];
		var par4 = $("cfg_filter").cfg_filter_par4;
		this.resetSelectedOption(par4, filter[3]);
		var par5 = $("cfg_filter").cfg_filter_par5;
		this.resetSelectedOption(par5, filter[4]);
	},

	cfgSuccMsgFunc : function(isSuccess) {
		/*
		if (isSuccess) {
			$("cfgSuccMsg").show();
			this.cfgSuccPrompt = false;
		} else {
			$("cfgSuccMsg").hide();
		}
		*/
		if (isSuccess) {
			Tips.show('配置选项修改成功!', 5);
			this.cfgSuccPrompt = false;
		}
	},
	
	signMsgFunc : function(isSuccess) {
		if (isSuccess) {
			$("signMsg").show();
			this.signPrompt = false;
		} else {
			$("signMsg").hide();
		}
	},

	rtCheckedData : function(filter, filtername) {
		if (!$('cfg_filter')[filtername]) {
			return "0,,,0,";
		}
		var dataArray = filter.split(",");
		if ($('cfg_filter')[filtername].checked) {
			dataArray[0] = 1;
		} else {
			dataArray[0] = 0;
		}
		return dataArray.join(',');
	},

	resetSelectedOption : function(par, filter) {
		for (var i = 0; i < par.options.length; i++) {
			if (par.options[i].value == filter) {
				if (!par.options[i].selected) {
					par.options[i].selected = !par.options[i].selected;
				}
			} else {
				if (par.options[i].selected) {
					par.options[i].selected = !par.options[i].selected;
				}
			}
		}
	},

	setMailCfgAddFilterValue : function() {
		var newFilter = new Array();
		newFilter[0] = 0;
		newFilter[1] = this.getSelectedOption($('cfg_filter').cfg_filter_par2);
		newFilter[2] = $('cfg_filter').cfg_filter_par3.value;
		newFilter[3] = this.getSelectedOption($('cfg_filter').cfg_filter_par4);
		newFilter[4] = this.getSelectedOption($('cfg_filter').cfg_filter_par5);
		return newFilter.join(',');
	},

	getRefuseAddress : function(selObj) {
		var ra = new Array();
		for (var i = 0; i < selObj.options.length; i++) {
			ra[i] = selObj.options[i].value;
		}
		return ra.join(",");
	},

	getSelectedOption : function(selObj) {
		var ra = new Array();
		for (var i = 0; i < selObj.options.length; i++) {
			if (selObj.options[i].selected) {
				return selObj.options[i].value;
			}
		}
	},

	getRadioCheckedValue : function(formObj) {
		for (var i = 0; i < formObj.length; i++) {
			if (formObj[i].checked) {
				return (function() {
					var _v = formObj[i].value;
					return _v == 'true' ? true : _v == 'false' ? false : _v;
				})(); 
			}
		}
		return "";
	},

	cfgMoveIn : function(s, d) {
		if (!IsEmail(s.value)) {
			return;
		}
		// d.innerHTML += '<option value="'+ s.value +'">'+ s.value
		// +'</option>';
		var v = s.value;
		s.value = "";
		new Insertion.Bottom(d, '<option value="' + v + '">' + v + '</option>');
	},

	cfgMoveOut : function(obj) {
		var list = new Array();
		var l = 0;
		var len = obj.options.length;
		for (var i = 0; i < len; i++) {
			if (!obj.options[i].selected) {
				list[l++] = obj.options[i];
			}
		}
		for (var i = 0; i < len; i++) {
			obj.options[0] = null;
		}
		for (var j = 0; j < list.length; j++) {
			obj.options[j] = list[j];
		}
	},
	
	// 设置用户的自定义签名图片
	setCustomSign: function() {
		var params = {
			x: position_sign[0],
			y: position_sign[1],
			width: position_sign[2],
			height: position_sign[3],
			email: UserSohuID,
			domain: 0,
			flag :0,
			filename: img_filename
		};
		_defun('/sign/act/ImageHandle', 'post', params, this.setCustomSignCallback.bind(this), this.setCustomSignFailureCallback.bind(this));
	},
	setCustomSignCallback: function(ret) {
		if (ret.is_success) {
			var imgname = ret.filename;
			image_signature_name = imgname;
        	$('demoimg').src = SIGN_ROOT + '/' + imgname+'.jpg?' + Math.random();
			$('previewArea').src = imgname + '?' + Math.random();
        	mailCfgClass.setMailCfgSignImg();
		} else {
			_dialog.alert({info: ret.message});
		}
	},
	setCustomSignFailureCallback: function() {
		_dialog.alert({info: '系统错误，请重试'});
	},

	getCfgNameByCfgId : function(_cfgid) {
		for (var i = 0; i < this.mailCfgList.length; i++) {
			if (this.mailCfgList[i].cfg_id == _cfgid) {
				return this.mailCfgList[i].name;
			}
		}
		return null;
	},
	showWBList: function(_id){
		$('tr_'+_id).hide();
		$('th_'+_id).show();
	},
	hideWBList: function(_id){
		$('tr_'+_id).show();
		$('th_'+_id).hide();
	},
 	resetValue: function(name){
		$(name).value='';
	},
	hiddenImg: function(){
		$('imgDiv').hide();
		$('bgDiv').innerHTML = '<img id="signImage" style="border: 1px none rgb(204, 204, 204); z-index: 1; display: block;" />';
	}
};
var mailCfgClass = new MailCfg();


var _LOGIN_OPTIONS = Class.create();
_LOGIN_OPTIONS.prototype = {
	
	initialize : function(){
		//直接进入邮箱的时候,this._lo = 1，否则等于0
		this._lo = null;
		this._update = null;
	},
	getResult : function() {
		var param = {
			'q' : Math.round(Math.random()*10000)
		};
		getLogin( param, this.getLOS.bind( this ), this.getLOF.bind( this ) );
	},
	
	getLOS : function( rets ){
		var ret = rets.evalJSON();
		if ( ret.status == 0 )
		{
			this._lo = ret.logintype;
			//alert( this._lo );
			var t = new Template( advancedFeatureTemplate );
			hiddenAllPanel();
			
			changeToolbarStyle();
			var data  = Array();
			data[ 'adf' ] = '<input type="radio" id="lo_mail" name="radiobutton" value="1"> 直接登录邮箱<br><input id="lo_card" type="radio" name="radiobutton" value="2"> 进入狐首卡片<br>';
			DOM.mailConfiguration.innerHTML = t.evaluate(data);
			
			if (  ret.logintype == 0 )
			{
				$( 'lo_card' ).checked = true;
			}
			if (  ret.logintype == 1 )
			{
				$( 'lo_mail' ).checked = true;
			}
			DOM.mailConfiguration.show();
			
		}
	},

	getLOF : function( ret ){
		// alert( '服务出现错误，该功能暂不可用。请稍后重试！' );
		_dialog.alert({info: '服务出现错误，该功能暂不可用。请稍后重试！'});
		return false;
	},

	setResult : function(){
		var new_value = $( 'lo_mail' ).checked;
		//直接进入邮箱的时候
		if ( new_value == false && this._lo == 1)
		{
			this._updateNewValue( 0 );
		}
		else if ( new_value == true && this._lo == 0 )
		{
			this._updateNewValue( 1 );
		}
		else
		{
			mailCfgClass.cfgSuccPrompt = true;
			mailCfgClass.initMailCfg();
		}
	},

	_updateNewValue : function( newValue ){
		var param = {
			'logintype' : newValue
		};
		setLogin(  param, this.setLOS.bind( this ), this.getLOF.bind( this ) );
	},

	setLOS : function( rets ){
		var ret = rets.evalJSON();
		if ( ret.status ==0 )
		{
			mailCfgClass.cfgSuccPrompt = true;
			mailCfgClass.initMailCfg();
		}
		else
		{
			return false;
		}
	}
};

var login_option = new _LOGIN_OPTIONS();
